package by.gusto.afisha;

import com.googlecode.androidannotations.annotations.Background;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.Fullscreen;
import com.googlecode.androidannotations.annotations.NoTitle;
import com.googlecode.androidannotations.annotations.ViewById;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.app.Activity;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.TextView;

@NoTitle
@Fullscreen
@EActivity(R.layout.splash_screen)
public class SplashScreenActivity extends Activity {

	private static final long TIME_TO_CLOSE = 3000;

	private static final long ANIMATION_DURATION = 1000;

	@ViewById(R.id.text)
	TextView mText;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		new CountDownTimer(TIME_TO_CLOSE, TIME_TO_CLOSE) {
			
			@Override
			public void onTick(long millisUntilFinished) {
			}
			
			@Override
			public void onFinish() {
				AlphaAnimation anim = new AlphaAnimation(1f, 0f);
				anim.setDuration(ANIMATION_DURATION);
				anim.setAnimationListener(new AnimationListener() {
					
					@Override
					public void onAnimationStart(Animation animation) {
					}
					
					@Override
					public void onAnimationRepeat(Animation animation) {
					}
					
					@Override
					public void onAnimationEnd(Animation animation) {
						mText.setVisibility(View.INVISIBLE);
						
						
						MainActivity_.intent(SplashScreenActivity.this).start();
						finish();
					}
				});
				mText.startAnimation(anim);
			}
		}.start();
		
		init();
	}

	@Override
	public void onWindowFocusChanged(final boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		if (hasFocus) {
			AlphaAnimation anim = new AlphaAnimation(0f, 1f);
			anim.setDuration(ANIMATION_DURATION);
			mText.startAnimation(anim);
		}
	}
	
	@Background
	public void init() {
		
	}
}
